package com.ihr360.insurance.controller.benefit;

import com.ihr360.commons.vo.PageData;
import com.ihr360.excel.entity.ExportParams;
import com.ihr360.insurance.entity.request.MemberPlanReq;
import com.ihr360.insurance.entity.request.StaffIdRequest;
import com.ihr360.insurance.entity.response.LedgerResponse;
import com.ihr360.insurance.entity.vo.MemberPlanVo;
import com.ihr360.insurance.service.DecreaseMemberService;
import com.ihr360.maven.plugin.ModuleCodeStore;
import com.ihr360.maven.plugin.annotation.FunctionDefinition;
import com.ihr360.maven.plugin.annotation.ModuleDefinition;
import com.ihr360.shared.advice.response.DisableResponseAdvice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 社保公积金方案
 *
 * @author david.wei
 */
@RestController
@RequestMapping("/decreaseMemberPlans")
@ModuleDefinition(mainModuleCode = ModuleCodeStore.Module.BENEFIT_CODE,
        mainModuleName = ModuleCodeStore.Module.BENEFIT_NAME,
        subModuleCode = ModuleCodeStore.Module.Benefit.LEDGER_STAFF_IN_OUT_CODE,
        subModuleName = ModuleCodeStore.Module.Benefit.LEDGER_STAFF_IN_OUT_NAME)
public class DecreaseMemberPlanController {

    @Autowired
    private DecreaseMemberService service;

    /**
     * feign接口
     */
    @FunctionDefinition(functionName = "获取减员列表", functionCode = ModuleCodeStore.Function.VIEW)
    @RequestMapping(value = "/member/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @DisableResponseAdvice
    public PageData<MemberPlanVo> getDecreaseMemberList(@RequestParam String companyId,
                                                        @RequestParam String userId,
                                                        @RequestBody MemberPlanReq req) {
        return service.getDecreaseMember(companyId, userId, req, req.getStaffIds());
    }

    /**
     * feign接口
     */
    @FunctionDefinition(functionName = "关闭台账，保存相应的减员记录", functionCode = ModuleCodeStore.Function.ADD)
    @RequestMapping(value = "/member/saveRecords", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @DisableResponseAdvice
    public void saveDecreaseMemberRecords(@RequestParam Long ledgerSummaryId,
                                          @RequestParam StaffIdRequest staffIdRequest) {
        service.saveDecreaseMemberRecords(ledgerSummaryId, staffIdRequest.getStaffIds());
    }

    /**
     * feign接口
     */
    @FunctionDefinition(functionName = "减员人员加入台账", functionCode = ModuleCodeStore.Function.ADD)
    @RequestMapping(value = "/member/add", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @DisableResponseAdvice
    public LedgerResponse addDecreaseMember(@RequestParam String companyId,
                                            @RequestParam String userId,
                                            @RequestParam Integer year,
                                            @RequestParam Integer month,
                                            @RequestBody MemberPlanVo vo) {
        return service.addDecreaseStaffToLedger(companyId, userId, year, month, vo);
    }

    /**
     * feign接口
     */
    @FunctionDefinition(functionName = "减员人员从台账中移除", functionCode = ModuleCodeStore.Function.DELETE)
    @RequestMapping(value = "/member/remove", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @DisableResponseAdvice
    public boolean removeDecreaseMember(@RequestParam String companyId,
                                        @RequestParam String userId,
                                        @RequestParam Integer year,
                                        @RequestParam Integer month,
                                        @RequestBody MemberPlanVo vo) {
        return service.deleteDecreaseStaffFromLedger(companyId, userId, year, month, vo);
    }

    /**
     * feign接口
     */
    @FunctionDefinition(functionName = "获取导出减员数据", functionCode = ModuleCodeStore.Function.VIEW)
    @RequestMapping(value = "/member/getExportData", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @DisableResponseAdvice
    public ExportParams<List<Object>> getExportExcelData(@RequestParam String companyId,
                                                         @RequestParam String userId,
                                                         @RequestBody MemberPlanReq req) {
        return service.getExportExcelData(companyId, userId, req, req.getStaffIds());
    }

}